<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring @RequestMapping 注解完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-header {
            background: #2d2d2d;
            padding: 8px 16px;
            font-size: 12px;
            color: #888;
            border-bottom: 1px solid #3e3e3e;
        }
        
        pre {
            margin: 0;
            padding: 16px;
            overflow-x: auto;
        }
        
        .parameter-card {
            background: white;
            border-left: 4px solid #667eea;
            padding: 20px;
            margin-bottom: 16px;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.05);
            transition: all 0.3s ease;
        }
        
        .parameter-card:hover {
            box-shadow: 0 8px 16px rgba(0,0,0,0.1);
            transform: translateX(5px);
        }
        
        .first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 8px;
            margin-top: 4px;
            font-weight: 700;
            color: #667eea;
        }
        
        .mermaid {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.05);
        }
        
        .example-number {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 32px;
            height: 32px;
            background: #667eea;
            color: white;
            border-radius: 50%;
            font-weight: 600;
            margin-right: 12px;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white">
        <div class="container mx-auto px-6 py-20">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    <i class="fas fa-code mr-4"></i>@RequestMapping
                </h1>
                <p class="text-xl md:text-2xl opacity-90 mb-8">
                    Spring框架中最核心的请求映射注解
                </p>
                <div class="flex justify-center space-x-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-layer-group mr-2"></i>Spring MVC
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-route mr-2"></i>URL映射
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-server mr-2"></i>RESTful API
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction Section -->
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12 card-hover">
            <h2 class="text-3xl font-bold text-gray-800 mb-6">
                <i class="fas fa-info-circle text-purple-600 mr-3"></i>什么是 @RequestMapping？
            </h2>
            <p class="text-lg text-gray-700 leading-relaxed">
                <span class="first-letter">@</span>RequestMapping 是 Spring 框架中用于映射请求的 URL 到方法或控制器类的注解。它可以用于处理 HTTP 请求，指定请求的 HTTP 方法、路径等。在 Spring MVC 中，@RequestMapping 通常用于标识控制器方法，用于处理用户请求并返回相应的响应。
            </p>
            <p class="text-lg text-gray-700 leading-relaxed mt-4">
                该注解可以在类级别或方法级别使用，具体取决于你希望如何映射请求。通过灵活的参数配置，开发者可以精确控制请求的匹配规则。
            </p>
        </div>

        <!-- Concept Map -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold text-gray-800 mb-6">
                <i class="fas fa-sitemap text-purple-600 mr-3"></i>概念关系图
            </h2>
            <div class="mermaid">
                graph TD
                    A[@RequestMapping] --> B[类级别映射]
                    A --> C[方法级别映射]
                    A --> D[参数配置]
                    D --> E[value/path]
                    D --> F[method]
                    D --> G[params]
                    D --> H[headers]
                    D --> I[consumes]
                    D --> J[produces]
                    B --> K[定义基础路径]
                    C --> L[定义具体路径]
                    F --> M[GET]
                    F --> N[POST]
                    F --> O[PUT]
                    F --> P[DELETE]
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Parameters Section -->
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12">
            <h2 class="text-3xl font-bold text-gray-800 mb-8">
                <i class="fas fa-cogs text-purple-600 mr-3"></i>核心参数详解
            </h2>
            
            <div class="parameter-card">
                <h3 class="text-xl font-semibold text-gray-800 mb-2">
                    <i class="fas fa-link text-purple-500 mr-2"></i>value / path
                </h3>
                <p class="text-gray-700">
                    用于指定映射的 URL 路径，可以是一个字符串数组，支持多个 URL 路径映射到同一个处理方法。这是最常用的参数，定义了请求的访问路径。
                </p>
            </div>

            <div class="parameter-card">
                <h3 class="text-xl font-semibold text-gray-800 mb-2">
                    <i class="fas fa-exchange-alt text-purple-500 mr-2"></i>method
                </h3>
                <p class="text-gray-700">
                    用于指定请求的 HTTP 方法，可以是一个 RequestMethod 数组。默认情况下，该参数为 RequestMethod.GET，表示只映射 GET 请求。支持 GET、POST、PUT、DELETE 等方法。
                </p>
            </div>

            <div class="parameter-card">
                <h3 class="text-xl font-semibold text-gray-800 mb-2">
                    <i class="fas fa-filter text-purple-500 mr-2"></i>params
                </h3>
                <p class="text-gray-700">
                    用于指定请求的参数条件，可以是一个字符串数组。可以指定请求必须包含的参数或参数值等条件，实现更精确的请求匹配。
                </p>
            </div>

            <div class="parameter-card">
                <h3 class="text-xl font-semibold text-gray-800 mb-2">
                    <i class="fas fa-heading text-purple-500 mr-2"></i>headers
                </h3>
                <p class="text-gray-700">
                    用于指定请求的 Header 条件，可以是一个字符串数组。可以指定请求必须包含的 Header 或 Header 值等条件，常用于 API 版本控制或认证。
                </p>
            </div>

            <div class="parameter-card">
                <h3 class="text-xl font-semibold text-gray-800 mb-2">
                    <i class="fas fa-file-import text-purple-500 mr-2"></i>consumes
                </h3>
                <p class="text-gray-700">
                    用于指定请求的 Content-Type 条件，可以是一个字符串数组。指定处理方法能够接收的 Content-Type 类型，如 application/json、application/xml 等。
                </p>
            </div>

            <div class="parameter-card">
                <h3 class="text-xl font-semibold text-gray-800 mb-2">
                    <i class="fas fa-file-export text-purple-500 mr-2"></i>produces
                </h3>
                <p class="text-gray-700">
                    用于指定响应的 Content-Type 条件，可以是一个字符串数组。指定处理方法能够产生的 Content-Type 类型，确保客户端接收到正确格式的响应。
                </p>
            </div>
        </div>

        <!-- Examples Section -->
        <div class="bg-gray-50 rounded-2xl p-8 md:p-12">
            <h2 class="text-3xl font-bold text-gray-800 mb-8">
                <i class="fas fa-code text-purple-600 mr-3"></i>实战示例
            </h2>

            <!-- Example 1 -->
            <div class="mb-10">
                <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                    <span class="example-number">1</span>
                    映射 GET 请求到处理方法
                </h3>
                <div class="code-block">
                    <div class="code-header">
                        <i class="fab fa-java mr-2"></i>HelloController.java
                    </div>
                    <pre><code>@RestController
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping(method = RequestMethod.GET)
    public String sayHello() {
        return "Hello, World!";
    }
}</code></pre>
                </div>
            </div>

            <!-- Example 2 -->
            <div class="mb-10">
                <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                    <span class="example-number">2</span>
                    映射指定参数的 POST 请求
                </h3>
                <div class="code-block">
                    <div class="code-header">
                        <i class="fab fa-java mr-2"></i>GreetingController.java
                    </div>
                    <pre><code>@RestController
@RequestMapping("/greet")
public class GreetingController {

    @RequestMapping(method = RequestMethod.POST, params = "name")
    public String greet(@RequestParam("name") String name) {
        return "Hello, " + name + "!";
    }
}</code></pre>
                </div>
            </div>

            <!-- Example 3 -->
            <div class="mb-10">
                <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                    <span class="example-number">3</span>
                    映射指定 Header 的 GET 请求
                </h3>
                <div class="code-block">
                    <div class="code-header">
                        <i class="fab fa-java mr-2"></i>InfoController.java
                    </div>
                    <pre><code>@RestController
@RequestMapping("/info")
public class InfoController {

    @RequestMapping(method = RequestMethod.GET, headers = "X-API-Key=myApiKey")
    public String getInfo() {
        return "This is sensitive information.";
    }
}</code></pre>
                </div>
            </div>

            <!-- Example 4 -->
            <div class="mb-10">
                <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                    <span class="example-number">4</span>
                    映射指定 Content-Type 的 POST 请求
                </h3>
                <div class="code-block">
                    <div class="code-header">
                        <i class="fab fa-java mr-2"></i>DataController.java
                    </div>
                    <pre><code>@RestController
@RequestMapping("/data")
public class DataController {

    @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public String processData(@RequestBody Data data) {
        // Process JSON data
        return "Data processed successfully.";
    }
}</code></pre>
                </div>
                